<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 --> 

	<link rel="stylesheet" type="text/css" th:href="@{/simditor/css/styles/simditor.css}" />
	<script type="text/javascript" th:src="@{/simditor/js/scripts/jquery.min.js}"></script>
	<script type="text/javascript" th:src="@{/simditor/js/scripts/module.js}"></script>
	<script type="text/javascript" th:src="@{/simditor/js/scripts/hotkeys.js}"></script>
	<script type="text/javascript" th:src="@{/simditor/js/scripts/uploader.js}"></script>
	<script type="text/javascript" th:src="@{/simditor/js/scripts/simditor.js}"></script>
    
    <link rel="stylesheet" th:href="@{/alllayui/layui/css/layui.css}"  media="all">
    <script th:src="@{/alllayui/layui/layui.js}" charset="utf-8"></script>
   
    
  
    <style type="text/css">
       .layui-form-selectup dl{
          top:42px;
          bottom:unset; 
       }
    </style>
</head>


<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加新闻</legend>
</fieldset> 

<div class="layui-form-item">  
      <label class="layui-form-label">新闻标题</label>
      <div class="layui-input-block">
            <input type="text" name='ntitle' id="ntitle" lay-verify="required" lay-reqtext="新闻标题为必填项" placeholder="请输入新闻标题" autocomplete="off"  style="width:900px;"   class="layui-input" >
      </div> 
 </div>


 <div> 
   <textarea id="editor" placeholder="" autofocus></textarea>
 </div>
 
 
<div style="height: 10px;"></div>

<form class="layui-form" action="">   
	<div class="layui-form-item">  
	       <div class="layui-inline">
	            <label class="layui-form-label">新闻类型</label>
	            <div class="layui-input-inline">
	                  <select name='newsType'    lay-verify="required">
	                      <option value="">请选择</option>
	                          <option value="0" >内部使用</option>
	                          <option value="1" >外部链接</option>
	                  </select>
	            </div>
	       </div>
	       <div class="layui-inline">
	            <label class="layui-form-label">评论权限</label>
	            <div class="layui-input-inline">
	                  <select name='allowComment'    lay-verify="required">
	                      <option value="">请选择</option>
	                          <option value="0" >开启评论</option>
	                          <option value="1" >关闭评论</option>
	                  </select>
	            </div>
	       </div>
	 </div>  
	 
     <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="subBtn">提交</button>
        </div>
    </div>
 </form>

<script> 
		var tools =[
		  'title'
		 , 'bold'
		  ,'italic'
		 , 'underline'
		 , 'strikethrough'
		 , 'fontScale'
		 , 'color'
		 , 'ol'             
		 , 'ul'             
		 , 'blockquote'
		 , 'code'            
		 , 'table'
		 , 'link'
		 , 'image'
		 , 'hr'             
		 , 'indent'
		 , 'outdent'
		 , 'alignment'
		];
		
		
		var editor = new Simditor({
		    textarea: $('#editor'),
		    toolbar:tools,
		    toolbarFloat: true,
		    toolbarFloatOffset: 0,
		    toolbarHidden: false,
		    upload:{
		        url: '/simditor/uploadPic',
		        params: null,
		        fileKey: 'editorPic',
		        connectionCount: 1,
		        leaveConfirm: '正在上传, 你确定要离开吗?'
		    }
			});

	</script>
    
<script>
    layui.use([ 'form'], function(){
        var thisIndex = parent.layer.getFrameIndex(window.name);
        var form = layui.form
            ,layer = layui.layer ; 

         
        var parentLayer = parent.layer;
        var pWindow = parent ;
        form.on('submit(subBtn)', function(data){
            var data2Send = data.field;
            data2Send['ntitle'] = $('#ntitle').val();
            data2Send['ncontent'] = editor.getValue();
            parentLayer.close(thisIndex);
            $.post("/orgnews/add",data2Send,function (res) {
                
                if(res.message == 'SUCCESS'){
                	var msg = '添加成功!窗口关闭';
                    parentLayer.msg(msg, {
                        icon: 1,
                        time: 2000
                    } );
                } else {
                	var msg =  '添加失败!窗口关闭';
                    parentLayer.msg(msg, {
                        icon: 1,
                        time: 2000
                    });
                }
                 
            },"json");
        });
        
      
        
    });

    function coverValue(coverValueColumn,chooseInfo) {
        //console.log("父页面");
        //console.log(coverValueColumn);
        //console.log(chooseInfo);
        let parse = JSON.parse(coverValueColumn);
        var valObj  ;
        if(chooseInfo){
            valObj = chooseInfo[0];
        }
        //console.log(valObj);
        for(let i=0;i<parse.length;i++){
            var coverObj = parse[i];
            setFormValue(coverObj.mTable,valObj[coverObj.rSql]);
        }
    }

    function setFormValue(componentId,val) {
        document.getElementsByName(componentId)[0].value = val;
    }

</script>

</body>